more efficient method
scripted update of code from master at f01f8c6 more efficient method