finished function writings

successfully functioned. added example run. but needs more comment on
code