improved check function