Little refactor and added docstrings and comments