edited javascript. transferred some lines of code into functions, effects still need work