added existing code and wrote some documentation.