Clean up connection direction checking code