Fixes to Python code