fix sorting and subcontainer handling