main logic isolated.