how does a refinery work