make the code in Write a little more logical, and add a missing test, though the code worked correctly before.