Reworked messageReceived()

Restructured messageReceived() to flow better
Added more documentation in the code