Added API description and refactored code