Large code cleanup; preparation for future update