Added validations

Shadowing outer local variable - `key`.