Removed obsolete code and refactoring