PortalKit: refactor most codes