Added more unit tests, fixed subtle class bug that they revealed.