Did various changes to tidy up code and organization.