split ports related code into a separate file