You really should stop jumping tasks. Make a backlog with all the things you have to do. In the beginning, these tasks will be very abstract. Then, take one item from your backlog. Keep working on it until it is done. Then close that item and take the next item from the backlog. Ideally you should do the items in order (FIFO: first-in, first-out)
If you ever feel like your code needs improvement while you work on it, but you think it is out of scope for your current task, create a new task and add it to the backlog. Since you work on your backlog, you will have to do that task sooner or later, but you can stay focused on what you are doing at the moment.
Try to focus on functionality first. Design, UX, API,... etc. do not really matter if your product cannot even do what you promised. First finish functionality, then think about how to improve your product. Most products needed many versions and releases to become "good". Just take a look at Android version 1. It was a pain to use, but the functionality was there. Since then a lot of releases were pushed out to create an excellent UX in addition to the stable base.
Later on, when your product has a functional base, you should use something like Zero Bug Development to keep producing stable results.
Marco Alka
Software Engineer, Technical Consultant & Mentor