Refactor and test whole word flipping