finished earlier refactoring but may need some more