Simplified Python code a fair bit

1. However, this slows down the algorithm by quite a bit.