Added helper function for error construction