Quickly hacked together while following a tutorial/analysis of how the real thing is implemented. Can't find the article anymore to link to it.