did a lot of refactoring