Fixed some errors in local optimizations