main flow working