Fixed some redirect errors and removed some duplicate code