More python 3 compat and tidying up