Faster solution thanks to Jeroen.