fixed flipdirection logic, had to do a second xor
removed flipDirection