Added state flags. Connection works!