Added tests and fixed bugs for null handling