remove code duplication in check.py