refactor ray cast