-- work in progress --
   * re-organised some of the code and removed redundant code.
   * updated some of the comment documentation.