Extract mkPort and mkState to the top level.