Merge pull request #92 from jocelynlih/paul

Fixed a few crash bugs that appear with full optimizations enabled
Accidentally trounced on Ankur's updates. Putting his work back.