Error and test refactor