extract checking process to a function