some refactor and add exeption