Fix for type checking issue (eg TypeError: Cannot call method 'toString' of null)