Fixed error in the auto_grant function