Big modification to deal with both message in and out
Signed-off-by: H.K. Wong <hkwong74531@yahoo.com.hk>