You always call `next_timer = -1` before calling schedule_timer() - this is error prone and needs refactoring.