ECOM-248 re-factoring code. updating test cases.