Added preprocessing and better error reporting