Moved around a lot of code in preparation for next changes.