several bugfix and improve