Added expand/contract logic.