Re-used code by splitting into a function