PERF: main function divided in several functions compute cumul of the mask values