Null check was checking the wrong variable