Adding more tests and improving robustness