Improved GA code