Big refactoring. Removed all warnings