added input algorithm.