minor cleanup and null check