Minor template fixes and code refactor

Look also github comments in files changed