Modified to use instrinsics. Works now!