Further tuning of python code