Fix some issues in the optimizer, so that purescript-promises can work properly.