start refactoring to pure python