A zipper based data structure for rearranging formulae