Fixed #6 Simplified handling of error and timeout messages
Additional error checking