add error raises and refactor