     return NULL;
 }
 
+static inline action_t * get_action(uint8_t actionno) {
+    linked_list_t * iterator = actions;
+    while (iterator != NULL) {
+        if (GET_MEMBER(iterator, action_t, actionno) == actionno)
+            return GET_ITEM(iterator, action_t);
+        NEXT(iterator);
+    }
+    return NULL;
+}
+
 static inline void prepare_action(alarm_t * alarm, actionspec_t * actionspec, bool invert) {
     time_t action_timestamp = alarm->timestamp + actionspec->offset;
+
     if (invert)
         action_timestamp += actionspec->timeout;
 


    alarm_t * alarm = get_alarm(alarm_req->alarmno);

    if (alarm == NULL) {
        alarm = new_alarm(alarm_req->alarmno, alarm_req->timestamp);
        alarm->name = strdup("Default");
        push_front(alarms, (void *) alarm);
        action_t * action;
        if (actions != NULL)
            action = GET_ITEM(actions, action_t);
        else {
            actionspec_t * actionspec = new_actionspec();
            // TODO This is a temp. default action
            actionspec->actions.flags.blink_backlight = true;
            actionspec->actions.flags.snoozable = true;
            actionspec->timeout = 0x7FFF;

            action = new_action();
            PUSH_FRONT(action->actionspecs, (void *) actionspec);
            PUSH_FRONT(actions, (void *) action);
            PUSH_FRONT(alarm->actionnos, COPY_ITEM(uint8_t, &action->actionno));
        }
        PUSH_FRONT(alarm->actionnos, COPY_ITEM(uint8_t, &action->actionno));
    }

    prepare_action(alarm, new_actionspec(), false);
    linked_list_t * iterator = alarm->actionnos;
    while (iterator != NULL) {
        uint8_t actionno = *GET_ITEM(iterator, uint8_t);
        linked_list_t * action_iterator = actions;
        while (action_iterator != NULL) {
            if (actionno == GET_MEMBER(action_iterator, action_t, actionno)) {

    action_time->alarmno = alarm->alarmno;
    action_time->timestamp = action_timestamp;
    action_time->actions = actionspec->actions;
    action_time->actions.flags.inverted = invert;

    if (insert_pos == NULL)
        PUSH_FRONT(action_times, action_time);
    else
        PUSH_BEHIND(insert_pos, action_time);

    if (!invert)
        prepare_action(alarm, actionspec, true);
}

