corrected speedup version, if loop breaks, no summe and thickness is considered