use more efficient method of removing trailing comma