added python 3 compatible code