You should be able to move this code outside of the if/else, and thus avoid duplicating it?