It feels like this new if statement should be able to be combined with the else part at 815 onward