complete working solution