refactoring code for looser coupling