finished minus the refactoring