This method could probably be split into several smaller methods for readability - not a blocker for this merge, but worth noting somewhere.