Updated error checking, minor bug fixes.