refactored and redirect problem fixed