Using die() inside libraries makes hard to trace/catch errors. What about throwing exceptions instead? If you want, I can make a pull request...