refactor some codes for sonar