Fixed variables scope collision

Fixed scope collision for variables `$key` and `$value`.