fix redirect code and make exception clearer