Pure Python implementation