Could you refactor this into a method? Seems like you're doing the same thing 3 times over and it would be easier to manage it if it's one place instead.