refactored JS to seperate view