Fixed few bugs
Added robustness