improved and refactored code, plus updated spec helper