Finalized code refactoring into separate methods