Fixed the possibility of encountering NullPointer.