Rewrote first cast to use withUnsafePointer.