refactored security and templates