Fixed variables scope collision

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

Fixed variables scope collision