fixed null pointer error
improved error reporting