Added code to perform flips in all directions