Nasty bug fix introduced nasty bug. Fixed, hopefully. Will write some more tests.