Fix key association

Look for an existing key only if 'deploy' is set to True and use it
only if it is not the one just associated.

This also includes some changes in variable names for more clarity.