Modified to use document reference