updating logging and adding exception handling