refactored and document the code nr. 2