I'll clean it up and post it on gist with some explanation.