Robustness

I've introduced much more checks on some functions, so that calling them with undefined/null values will not crash.