Fixing checkstyle, and remove duplicated code