Little refactoring, and added some docstrings