commented important elementes for debugging purpose.  fixed random generateor