Fixed many bugs and made more modular

Bugs such as numbers with letters in them as well as high and low
numbers was fixed. I also made the code more modular with a couple
functions to help get rid of all the clutter in main.c.