new feature and bug fix

upgrade from the mian branch