Before doing any more coding, can you write out in your native language exactly what it is you expect this program to do?
My criteria for good software:
- Does it work?
- Can someone else come in, make a change, and be reasonably certain no bugs were introduced?