added comments and cleaned up js file