You need to spend more time in Plan mode. Ask it to make diagrams or pseudocode of whats and hows, iterate on that and then Accept Edits.