added some comments and re-adjusted some code.