refactored
added testcase.