Cosmetic changes + a missed try/catch

Comparing to the reference code, some cosmetic changes to make it look
more similar. Also a try/catch was missed around the resetting of the
message received callbacks.