refactored the code and updated the specs