refactored to expose error codes in a public type