Major code rewrites and organization

Major code rewrites and organization, pleasing to the eye :D