Refactored the formQueryUrl method