add defensive programming