removed unused statements and added null check for datatype