A bunch of refactoring...