Compatible with Python2 + minor changes