Cleaned code relative to error handling