Improve Sympify

Also fixes #295.

The bugs fixed in this PR were triggered by the script in #295.