Fixes to return error codes