Towards a fix of #102.

I think this is looking good, just need to add the tests.