Some cleanup and added third referrer case.