Replaced returns and error calls with exceptions