PortalKit: refactor the build logic