Refactored label code into a function.