Minor cleanup and improvements, some fixes for python3 comparability