better error handling and url encoding management