Fix bugs in ks_db_{in,de}cr()
Unit test for ks_db_{in,de}cr()