enhanced error handling

added enhanced error handling