Cleaned up templates, added more security, other fixes