refactoring load and templates
refactoring to global....
still refactoring clause checking