Removed unnecessary code and improved  various methods.