Fixed a crash when removing modal view controllers.

This fixes #161.