The changes that you've been making to the code are a process called refactoring. The important aspect of refactoring is that the resulting behaviour of the code remains unchanged to the user.
All developers refactor their code, where they look for problems in the existing code and find ways to reduce or remove those problems.
Later on you might get in to test-driven development, where a simple small test is written for the next tiny feature that you want to write code for. The test will fail because you haven't written the code for it yet. Then you write the code to make that test pass, and then while the tests all pass, you refactor the code to improve how it's structured.
That fail/pass/refactor system forms a tight and stable loop, that lets you develop quite rapidly, in a stable manner, and whenever the code is in the pass or refactor stage you have fully working code.