[#482] Add docstrings
[#482] Refactor to reduce code duplication