changed js to have functions