minor refactoring, improved error messages and warnings