'expand' fixes and some cleanup to python files