A merge of all of the available PR's plus a bit more code on top. It often works. Plenty of TODO's left.