added 'flip' function