I'm not quite sure how it would work because I'd have to try it and see, but see if you can make a method that encapsulates the common functionality of these two code blocks.