Mostly working, at last. Some TODO for minor improvements here an there.