refactored, commented