Readded generic database code