Added another null check in scanStack