migrate most code out into .cpp files