smarter redirect detection

Fixes #7.