Adding loop structure and templates