Slight algorithm adjustment