refactoring of js app