Performance improvements and better error messages