typo fix and better checking of variable