separating policy code from redirection code and adding some tests