@Override
    public void update() {

        for (TimerTask task : new ArrayList<TimerTask>(tasks)) {
            if (task.getElapsed() < 0) {
                cancel(task);
            } else {
                task.elapse();

                if (task.getPeriod() <= 0 && task.getElapsed() == task.getDelay()) {
                    task.run();
                    cancel(task);
                } else if (task.getPeriod() > 0 && (task.getElapsed() - task.getDelay()) % task.getPeriod() == 0) {
                    task.run();
                }
            }
        }
    }