fix nullpointer exception in some cases
fix nullpointer exception on first run