Refactor, add JSHint and tests