Added error handling, updated image storing