Security refactor Phase 2