Reworked where variables are defined to aid memory reuse