fixed this and added a test for it