Some cleanup and refinement