Algebra code factored out as a trait