Moved the declaration of retval to the correct scope