JSHint errors + refactoring