A lot of refactoring, moved all common parts to functions
minor corrections, more refactoring
more refactoring and corrections
implemented timers bounded to branches; only they are used