change to pure python implementation