refactoring and refine test based on sonar and pitest