Removed unused stuff, refactoring of the rest