Added timeout. Added error message. Set up state paradigm.