commenting and added some checking