refactoring into js classes