Minor improvements

The `Use kv var in for loop` commit is an actual bugfix. The other 2 are minor improvements.