Main features complete

Added nonfunctional compatibility for refraction.
Cleaned up some code.