more tidying and better errors