Polished and debugged, and added documentation

Ran pylint, pep8, etc., and fixed code as necessary.