improve test case and make program more robust