fix typo and add some conditions