Rearrange packages and correct flags