commented and refactored