Sanity checks and parameter replacement.