fixing and cleaning the code