lots of little refactorings