Cleanup code, and split into separate files.

Use Meteor._debug for logging.