Revert "Fix expander and optimizer bugs"

This reverts commit ff26fff0e9f2dd2384e3092e76bd7daefc348292.