Refactor and testcases
test