I don't like having to do multiple nested loops... I feel there should be a better way to just check linearity.