Fix for python3; and optimize imports