refactored js to unscope things not needed in the view