Refactor handleMessage to not be one massive lump.