Fixes bugs in random mode