added lots of explanatory comments