this should be nearly working
scripted update of code from master at 50d2599 this should be nearly working