manage buffsize and count curly brackets to fix #19 and #20