updated the error check - RETVAL wasn't checked on error