Algorithm speed up