remove nasty perl script, replace with pure python function