Replaced die()-calls with exceptions where appropriate.