updated javascript file to be more readable/maintanable