Improve robustness and logging