fixed nullpointer exceptions, improved error messages