Upgraded error handling