misc cleanup + optimization