2 bugs fixe + minor perf improvements