Past due tasks counter bugfix and small refactoring