Added error detection and messages.