Refactoring input.js