Refactor code for clarity.
Add a self-test routine to the startup procedure.