Replaced print error statements with exceptions