updated functions to return error codes