move error handling into package