Fix problems identified by jshint and code review
Extract source code for core modules