Can you refactor this so that the code is not copy pasted? How about having a private method that takes the array of statements and returns the transformed statements.

I'm happy to do this if you want.