Added unittest for custom KeyValueSource implementations and fixed bugs according to that