Refactor random