MAINT: fix pyflakes issues.
MAINT: address review comments on gh-3512 by Warren and Denis.