Fix multiplying event listener in input field. Refactor and simplify JS.