Added handling of redirect urls, more error handling