various enhancement + fix very insidious bug