Extracting more methods and fields to make the main algorithm simpler