Fixed variables scope collision

Fixed scope collision for variables `$key` and `$value`.
Merge pull request #146 from Ingannatore/patch-4

Fixed variables scope collision