Completely rewrote and made the program functional