Removed goto statement and maintained the logic