simplify security and refactor code