NullPointer fixed && code quality improvement