use a class.
make main algorithm a big, stateful, class.
whitespace.
add comments.