null check and better error message