Initial code and tests for local optimizations