small optimizations...about to merge in master