changed die to throw exceptions instead

For more graceful errors