added some documentation and did some refactoring