added documentation and program logic at end