Add main template
Implementation of the algorithm