limited the algorithm to not take too long