cleaned and checked code