Security layer refactored