Fixed code executing after redirect