Added more docstrings. Input validation.