Refactored code and documented types