Create CELL_STATE_* constants
Refactor code into two new functions