Fixed code so all unittests pass.