Current logic produces error messages that are not very useful for debugging. This needs to improve.