Fixes to make code work under python3