Refactor tasks scheduling