fixed a ton of stuff for the template functions.