Making a big refactor on code and correcting some Sonar issues