Significant refactoring of the optimizer module
Improved async support and easier code maintenance