Added some error checking, more config, some clean up