An algebraic approach to form factors