Added comments
Fixed null pointer exceptions