Modify utility function to prevent byte overflows