Adding documentation and refactoring variable names