Move lock and unlock to CellRef (removes duplicate code)
Added an isLocked() function to cellref, and changed code to use it.