Separated out the rayhandler creation into own method.