Separate these out into a few lines and use scratch variables where appropriate.