Fixed test cases and fixed null pointer issue