Bit of robustness and code cleanup