Fixed some null/undefined-checking problems