Refactored code and added a couple docstrings.