Added documentation comments.
Optimised code.