Added redirect argument to JSON request and improved error messages