Lots of refactoring, now uses JSDoc and started unit tests