cleaned and integrated

applied optimization