Fixed. This time with unit tests, seeing as my brain is not working.