Start of cleaned-up implementation using data types instead of tuples.