patched to allow custom assign key value function