Python 3 compatbility fixes