Fixed flip() implementation