Removed obsolete code and did some refactoring