refactored formatHMS routine to allow for better memory management