Fixed previous commit, fixed a bug, added a test.