Extension-ized version of http://stackoverflow.com/questions/16992339