Try solution from https://coderwall.com/p/wmyqbw