fix a bug and add a test to check that it's fixed