Move URL definition out of function
Wrap and clarify too long error message
Better variable name
Fixed indentation
Allow to generate key only if it does not exist
Wrap long line