improve robustness, refactor, tweaks