Refactored input js