Making the code a bit more null hardy
Fixing unit tests