Fixes #135 Querying optimizer to loop until optimizations complete