This method seems too complex - can you split it in multiple private ones?