Moved hostname parsing and request creation into its own function