made null checks for query