Adding some cleaner error checking.