Fixes #1604: fixed URL and cookie problems. Refactored tests.