lots of code refactoring