Added check for null visit records. Minor updates