improve compatibility across python 2 and 3