(http://csharppad.com/gist/9252122)