Modified and added comments.
Added documentation and in-line comments.