Some semantic cleanup and reorganization