Fixed for python3 compatibility (tested against 2.7 + 3.3)