Cleaned up code. Added complete randomness to the outputfile