this line is repeated in both then and else blocks. Can refactor it outside.