Created port.h, plus some code removal and refactoring.