Remove unused code and use safer nil check