use a common structure to create code for both directions
use a common structure to create code for both directions