Generalize code to make it python3 compatable.