Some python optimisations