Fix #41

This seems to solve #41. Let me know if my understanding of how this should work is wrong.