brian's optimizations