refactored null checks