bug fixing and robustifying