some more comments and code optimization.
comments added.