Refactors into a class.
Moves class to its own file.
Simplifies main.php file.
Updates doc.
Merge pull request #1 from bbene/dev

Refactoring into class.