Updated Logic and test code

Updated Logic and test code