Improve the implementation of flip'