Front end complete. Start of refactoring.