@Override
    public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
        try {
        	if ( !(args[0] instanceof LogicalFormula))
        		throw new JasonException("The first argument of if must be a logical formula.");
        	
            LogicalFormula logExpr = (LogicalFormula)args[0];
            PlanBody whattoadd = null;
            
            Iterator<Unifier> iu = logExpr.logicalConsequence(ts.getAg(), un);
            if (iu.hasNext()) {	// .if THEN
	            if ( !args[1].isPlanBody())
	        		throw new JasonException("The second argument of if must be a plan body term.");
                whattoadd = (PlanBody)args[1];
            	un.compose(iu.next());
            } else if (args.length == 3) { // .if ELSE
	            if ( !args[2].isPlanBody())
	        		throw new JasonException("The third argument of if must be a plan body term.");
                whattoadd = (PlanBody)args[2];
            }

            if (whattoadd != null) {
	        	IntendedMeans im = ts.getC().getSelectedIntention().peek();
	        	PlanBody ifia = im.getCurrentStep();
	        	whattoadd.setAsBodyTerm(false);
	        	ifia.add(1,whattoadd);
            }
            return true;
        } catch (ArrayIndexOutOfBoundsException e) {
            throw new JasonException("The 'if' has not received the required arguments.");
        } catch (JasonException e) {
            throw e;
        } catch (Exception e) {
            throw new JasonException("Error in 'if': " + e, e);
        }
    }