code cleanup; remove unneeded globals; fix check for None (== None → is
None)