Code refactor.

Code refactor and fixing the checkstyle and pmd warnings.