set onMessage prototype & code cleanup