improved logging and handled nullPointerExceptions