cleanup

cleanup - moved all optimization up top