Added exceptions to handle errors