fix the ray tracing function