Refactor and fix many checkstyle errors