Added Connected device state, cleaned up test program, added some error handling