Refactoring some refraction code computation