.js needs refactoring