Still need to neaten up, pretty much done.
Fixed the bug, it works now, still needs documentation.