Added complete error handling