fixed nullpointer, logging and exception handling