Improved template logic.
Added TemplateFactory
More separation of items in template
Fixed a critical nullpointer bug