Implemented some composition handling in apply (in term factory).