refactored code

applying best js practices to be more politically correct.