rewrite this so it actually works

grabbed this from somwhere, it doesn't work reliably