Fixed 1st line issue (redundant space). Reworked template generation algorythm.