fixed flags, handling of failed sends, checking for states and other
stuff