Final version (unless there is time later)
fixed the null bug