Fixed a few bugs, template stuff