Fixed python3 incompatibility. Added test to repro issue on 2.7