move common flow check part to a separate function