Utility function to add perfdata

Plus a little refactoring.