random logic revised, still has bug