adding some more robustness to the functions