refactor and adding pretests