Make python package more robust

Hope I got this right.