Think before you write. When I get an idea I intentionally don’t write anything. I wait – sometimes for years – until I have a decent idea of where the plot is going and what my characters are like. I still don’t write a word until I know my ending. You can always change the ending – it’s your book – but you need something to shoot for. Then I spend months writing an outline that ends up being the book in shorthand. This way I spot plotting problems before I’ve written 400 pages and have to rip up everything. The published book is usually different from the outline but outlining is very important, especially for a mystery or thriller where everything has to make sense at the end. I write a first draft to get my ideas on paper. I assume it is not publishable. Then I rewrite, rewrite and rewrite again for quality.
One more thing. Being a writer is being rejected. But don’t get discouraged. If you like writing, keep doing it. Most famous published writers have a lot of unpublished manuscripts that probably should not have been published but they kept working until they perfected their craft. Great tennis players and pianists aren’t great when they start out.