Refactored code. Main.c still needs some work.