updated slightly the code