Removed duplicate SQL statements to calculate record counts