Fixed a bunch of exceptions and added a template