void resume(boolean stopByTimeout) {
            try {
                // unregister (for not to receive intentionAdded again)
                c.removeEventListener(this);

                // add SI again in C.I if it was not removed and this wait was not dropped
                if (c.getPendingIntentions().remove(sTE) == si && !c.getIntentions().contains(si) && !dropped) {
                    if (stopByTimeout && te != null && elapsedTimeTerm == null) {
                        // fail the .wait
                    	PlanBody body = si.peek().getPlan().getBody();
                    	body.add(1, new PlanBodyImpl(BodyType.internalAction, new InternalActionLiteral(".fail")));
                    } 
                    si.peek().removeCurrentStep();
                    if (elapsedTimeTerm != null) {
                        long elapsedTime = System.currentTimeMillis() - startTime;
                    	un.unifies(elapsedTimeTerm, new NumberTermImpl(elapsedTime));
                    }
                    if (si.isSuspended()) { // if the intention was suspended by .suspend
                    	String k = suspend.SUSPENDED_INT+si.getId();
                    	c.getPendingIntentions().put(k, si);
                    } else {
                    	c.addIntention(si);
                    }
                }
            } catch (Exception e) {
                ts.getLogger().log(Level.SEVERE, "Error at .wait thread", e);
            }
        }