algebra creation function now recursive