extracted javascript methods and functions, removed unused variables, and renamed variables to reflect what they do