Complete re-write of the whole lib.