cleaned up js code based on code review