Fixed ZeroDivisionError for empty databases