Add more null checks, fix bugs.