Hopefully fixed #62.

Somewhat tested, but may not entirely work.
Merge pull request #63 from bearbin/patch-2

Hopefully fixed #62.