Fixed some nil-pointer crashes