Detecting null object being queried and returning default value