Move the code out to a external function