Added more sanity checks and added info to exception messages.