Converted Python Version 2 code to Version 3