made some improvements with exceptions