Try using erl_syntax to manipulate the syntax tree instead