I just copied some [code I found sitting around](https://gist.github.com/4508265), but I can try to fix this. ;)