Preparing algorithm.