Finally, a working solution.