finished Template alorithm
finished Template alorithm