made changes and cleaned the code