Imporved database code