Cleaned up and added test for case that I was originally trying to solve