Better portfile detection and handling