Made things slightly more abstract with constants; removed cruft; added inbound/outbound stuff.