Fixed writing to a file descriptor condition.
Added a loop condition to check for existence of any active multiplex command.