Added better generation algorithm