Updated incompleted code + python3 fixes.

Incorrect code committed due to previous commit.
Also updated code to truly run on python3.