Fixed a bug with the last fix. And added a test to make sure it's actually fixed right this time.