applied patch from 'fix-redirect' branch