Added tests; Refactored application.js
refactored code