Refactor open-cells function