Final working solution.