Refactoring, cleanup, getting shared code working