Fixed some PMD violations by refactoring