translated from python