extracted javascript code into class