Fixed picked from EnTeQuAk's work on python3 port.