Major cleanup. Needs more work.