check nullpointer + fix "Address already in used" exception