bugs treated and some code edited