Clean up code to precent warnings

Remove unnecessary import of ToJSON
Change import of Map to import Map (instead of import Map(..))
Change names of max, queue and messages to max_, queue_, messages_
  to prevent shadowing warnings