Use put instead of add

Updated setKeyValue to use put instead of add (was crashing), with some other minor updates.