added conditional optimizations