refactor based on testcases