some more exception handling, hopefully more robust now