try to implement xnrand's fix take 2