Help me with this tax question

Non taxable exchange of real estate B: FMV 400,000 Mortgage (100,000) W: FMV 525,000 Mortgage (225,000) If B's adjusted basis was 240,000, compute B's realized gain, recognized gain, basis in W. I calculate realized gain is 160,000, recognized gain is 100,000, basis in W is 465,000. Could anybody tell me if my calculations right or wrong? Please reply with detailed calculation, thank you!!!