Fixed handling of empty result sets