a completed flow and fix bugs