fixed some errors (added refcounting for db and cursor, added whack call for pileup)