Fixed database code