optimization with the search function and implemented the port requirement