Tidied up the rand handler a bit