fixing a lot of bugs, and testing bdb