Fix: Make sure no-unused-vars doesn't get confused by nested functions

Tried implementing the fix that @ilyavolodin suggested on #584.