Moved some error checking