Should fix issue #54. Needs testing.