added Random number generator, cleaned up code.