Error handling added and cleaned up a bunch of other files.