Code cleanup, better null handling.