Python backend cleanup and fixes