second round of pure-python implementation