Debug fixes, better unit test