refactoring and reorganizing security module