clean up source a bit, add docs, use logger

Some basics:
* remove use of console.log in favor of logger
* remove lots of dead code
* add some comments