Fixed another py3 bug - my bad. Also moved type checking further down