Improving logical flow to minimise code