better error handling and add a test for images