Code Cleaning, threads and random