PortalKit: refactor codes