Probably working solution for problem12