Complete port (actually a rewrite) to 1.7.10!