Refractored changes along with added Tests