handle more cases

and added some comments