Refactor Ray constructor.