Refactored python3 support