Big refactoring & cleaning up.