Supports key and value functions

Fixes #1032