Fixed yet another stupid bug. Need more tests.