Implemented cell flipping logic