port WIP, needs finishing.
ported to 1.7.10; needs testing