cleaned and prepared code