Some reordering and cleanup