Added check for empty tables.