refactoring security check code