Improved error handling, cleaned up examples