Reshuffled ray tracing code to make reflection/refraction easier.