finished major refactoring