refactor and add spec