Use pinfo->fd->flags.visited and refactor

Signed-off-by: Simon Marchi <simon.marchi@polymtl.ca>