Bug fixes around error 500s