bug fixes for optimization