WARNING: UNSTABLE. READ CODE PRIOR TO USE. Added template registration functionality