You basically repeat the same code three times.
Put it in a function and call that three times?