Corrected wrong conversion between in/out flags and direction enum
Corrected in/out processing in rules for ports - fixes #409