working solution and some comments