Added more little optimization. The execution time is 6 seconds in HD scratch