Fix an error when data is empty
Clean database code