added error checking after preprocessing