refactoring a js app to oo