update

added comments.
moved functions and variables inside other function.
rewrote some

rewrote while() to make source easier to understand