refactor based on sonar