Updated and working solution