Updated with comments from where some code ideas were apdapted from.

Signed-off-by: dd1965 <david.dessardo@bigpond.com>