Bugfix for issue #37

To be honest, I don't have a high degree of confidence in this bugfix. However, it does appear to fix issue #37 (again).

Feedback wanted.

This is where I'm unsure. I could be introducing memory leaks here.