refactored js and view