fixed some issues come to light when running the testcases