Improving a code by implementing functions.