Improve null safety of boolean check