Adding error handling