First pass at major refactoring & cleanup