Added some error handling (mostly for development).