Some cleanup and rearrangement