refactoring js code
js is looking a lot neater now