Big refactoring to improve quality