reimplement with TDD

Used a very simple testing "framework": it runs the tests first,
and if there were no errors, it starts the application.
So I'm always sure that the application works.