fix a lot of bugs in indexing and caching
ensure error message is a string
minor shifting