null handling and minor tweaks