Fixed the IndexError with empty db