lots of corrections and removing unnecessary code