Error checking works

Now I just have to get rid of main, and replace it with a different function