Added exception handling for empty datasets