reworked code to python 3 style