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