can you move the ``$key`` assignment to before the if statement?