refactor out errors