refactoring - lots of it