Cleanup local usage and add null check

http://openeye.openmods.info/crashes/e13ceca5ef849cfb091e5b77d462a5dd