Bunch of fixes in db code. Some issue still with stream deserialization.