tiny bug in the last commit. check for null as well