Refactoring complete and working