refactoring to make spy working as mock