Added refraction
Cleaned up code