refactoring js to be less coupled, using interfaces