rewrite with python wrapper