pure python implementation