added documentation and did some refactoring