Fixed up the template loading, and cleaned up some stuff