Reducing repeated code