Refactoring code clean up

Find a cleaner way of expressing the loop comprehension
Refactoring clean up

Cleaned up the javascript in the template