changes for database support. (still need to put threading locks in place, but it at least works)