Fixed bug, made small improvements with template definitions