refactored this for better implementation

fixed unit test to the way it was before