Removing duplicated code and reducing checkstyle errors.