Refactor security