bug fixed: do not write a comma after the last layer