GC-91: Refactoring of the function optimization methods. Optimization methods don't throw exceptions anymore.