New source code for second layer templates computation