Bugfix: was returning inside the for loop instead of after it
Added some missing template parameters