Can you refactor this & split into 2-3 `private` methods to make the code more readable? Thanks!