Removed unused code, refactored some other code