Refactor label utilities for performance

Speed up label utility functions by 250%.