fix the end comma logic