refine unit test and logic