adding support for optimize operation and unit tests to go with