Fix copy-paste error. Don't try to unset a variable that isn't set.
Fix exception types and messages, fix parameter order if short urls is false.
Clean up and update tests.