Added faster Python implementation.