Added some comments and set a few paramaters const.