refactor berkdb stuff