added testing, misc robustness fixes