refactor null protection to follow ecma5