fixing some small things with error handling and adding an example