refactored js code to perform different action on load up