added better logic for iterating through hostname parameters