moved inline js code to anonymous functions